import forEach from 'lodash/forEach';
import defaults from 'lodash/defaults';
import filter from 'lodash/filter';
import './Element'

var hasClass = function(el, className) {
    if (!className) return false;
    if (el.classList) {
        return el.classList.contains(className);
    } else {
        return new RegExp('(^| )' + className + '( |$)', 'gi').test(el.className);
    }
};
var addClass = function(el, className) {
    if (!className) return;
    if(hasClass(el,className)) return
    if (el.classList) {
        el.classList.add(className);
    } else {
        el.className += ' ' + className;
    }
}

var removeClass = function(el, className) {
    if (!className) return;
    if (el.classList) {
        el.classList.remove(className);
    } else {
        el.className = el.className.replace(new RegExp('(^|\\b)' + className.split(' ').join('|') + '(\\b|$)', 'gi'), ' ');
    }
}

export default {
    forEach,
    filter,
    deepExtend:defaults,
    hasClass,
    addClass,
    removeClass,
}